package com.imooc.framework.thread;

public class SyncDemo {
    public static void main(String... args) {
        //同一个类，不同的锁对象,不阻塞
//        SyncThread syncThread1 = new SyncThread();
//        SyncThread syncThread2 = new SyncThread();
//        Thread A_thread1 = new Thread(syncThread1, "B_thread1");
//        Thread A_thread2 = new Thread(syncThread2, "B_thread2");
//        A_thread1.start();
//        A_thread2.start();

        //同一个类，同一个对象，非同步代码和同步代码，不阻塞
//        SyncThread syncThread = new SyncThread();
//        Thread A_thread1 = new Thread(syncThread, "A_thread1");
//        Thread A_thread2 = new Thread(syncThread, "B_thread2");
//        A_thread1.start();
//        A_thread2.start();

        //同一个类，同一个对象，同步方法和同步代码阻塞
//        SyncThread syncThread = new SyncThread();
//        Thread A_thread1 = new Thread(syncThread, "B_thread1");
//        Thread A_thread2 = new Thread(syncThread, "C_thread2");
//        A_thread1.start();
//        A_thread2.start();

        //同一个类，同一个对象，同步方法和同步代码、静态同步方法和静态同步代码不阻塞
        SyncThread syncThread = new SyncThread();
        Thread A_thread1 = new Thread(syncThread, "B_thread1");
        Thread A_thread2 = new Thread(syncThread, "C_thread2");
        Thread A_thread3 = new Thread(syncThread, "D_thread2");
        Thread A_thread4 = new Thread(syncThread, "E_thread2");
        A_thread1.start();
        A_thread2.start();
        A_thread3.start();
        A_thread4.start();
    }
}
